﻿using UnityEngine;
using UnityEngine.Events; 

namespace XFGameFramework
{ 
    public class TimerObject : MonoBehaviour
    {
        // Fix编码
        [Tooltip("延迟时间")]
        public float delay;
        [Tooltip("事件回调")]
        public UnityEvent Action;

        private string Key
        {
            get
            {
                return GetHashCode().ToString();
            }
        }

        private void OnEnable()
        {
            TimerManager.DelayInvoke(Key, OnAction, delay);
        }

        private void OnDisable()
        {
            TimerManager.CancelInvoke(Key);
        }

        private void OnAction()
        {
            Action?.Invoke();
        } 
    } 
}